package com.management.controller;

import com.management.po.Post;
import com.management.service.DeptService;
import com.management.service.PostService;
import com.management.service.SectionAndPostService;
import com.management.service.SectionService;
import com.management.vo.DeptVO;
import com.management.vo.SectionAndPostVO;
import com.management.vo.SectionVO;
import org.apache.log4j.Logger;
import org.hibernate.validator.internal.engine.MessageAndPath;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

/**
 * @author ls
 * @category
 * 内部公司控制器
 */
@Controller
public class InteriorController {
    Logger logger = Logger.getLogger(InteriorController.class);
    @Resource
    DeptService deptService;
    @Resource
    SectionService sectionService;
    @Resource
    SectionAndPostService sectionAndPostService;
    @Resource
    PostService postService;
    @RequestMapping("/list")
    public String list(int companyId, Model model){
        logger.info("进入list控制器");
        List<DeptVO> list =  deptService.findByCompanyId(companyId);
        List<Map<String,Object>> lists = new ArrayList<>();
        if (list!=null){
            for (DeptVO DV : list){
              int deptId =  DV.getDeptId();
                List<SectionVO> sectionVOList = sectionService.findByDeptId(deptId);
                if (sectionVOList!=null){
                    for (SectionVO SV:sectionVOList){
                        int sectionId =SV.getSectionId();
                        List<SectionAndPostVO> sectionAndPostVOList = sectionAndPostService.findBySectionId(sectionId);
                        if (sectionAndPostVOList!=null){
                            for (SectionAndPostVO SPV : sectionAndPostVOList){
                               Map<String,Object> map = new HashMap<>();
                               map.put("dept",DV);
                               map.put("section",SV);
                               map.put("post",SPV);
                               lists.add(map);
                            }
                        }
                    }
                }
            }
        }
        model.addAttribute("lists",lists);
        return "insidelist";
    }

}
